package com.news.service.impl;

import java.util.List;

import com.news.entity.Admin;
import com.news.entity.News;
import com.news.entity.Review;
import com.news.entity.User;
import com.news.service.ReviewService;
import com.news.dao.ReviewDao;
import com.news.dao.impl.ReviewDaoImpl;

public class ReviewServiceImpl implements ReviewService {
	
	ReviewDao reviewDao = new ReviewDaoImpl();

	//重写查询全部方法，如果reviewlist长度为零，返回null
	@Override
	public List<Review> queryAll() {
		// TODO Auto-generated method stub
		List<Review> reviewlist = reviewDao.queryAll();
		if (reviewlist.size() == 0) {
			return null;
		}
		return reviewlist;
	}

	//重写查询单条评论方法,返回Review,如果没有查到数据，返回null
	@Override
	public Review queryReview(int reviewId) {
		// TODO Auto-generated method stub
		Review review = reviewDao.queryReview(reviewId);
		if (review.getReviewId() == 0 || "".equals(review.getReviewId())) {
			return null;
		}
		return review;
	}

	//重写删除单条评论方法
	@Override
	public Boolean deleteReview(int reviewId) {
		// TODO Auto-generated method stub
		int num = reviewDao.deleteReview(reviewId);
		if (num == 1) {
			return true;
		}
		return false;
	}

	//重写删除多条评论方法
	@Override
	public Boolean deleteReview(int[] reviewId) {
		// TODO Auto-generated method stub
		int num = reviewDao.deleteReview(reviewId);
		if (num == reviewId.length) {
			return true;
		}
		return false;
	}

	//重写修改单条评论方法，根据成功或失败返回布尔值
	@Override
	public Boolean updateReview(Review review) {
		// TODO Auto-generated method stub
		int num = reviewDao.updateReview(review);
		if (num == 1) {
			return true;
		}
		return false;
	}

	//重写添加单条评论方法，根据成功或失败返回布尔值
	@Override
	public Boolean insertReview(Review review) {
		// TODO Auto-generated method stub
		int num = reviewDao.insertReview(review);
		if (num == 1) {
			return true;
		}
		return false;
	}


	// like模糊查询方法,若没有数据，返回null
	@Override
	public List<Review> likeSelectListReview(Review review) {
		// TODO Auto-generated method stub
		List<Review> reviewList= reviewDao.likeSelectListReview(review);
		if (reviewList.size() == 0) {
			return null;
		}
		return reviewList;
	}

	//根据userId获取user,如果没有值，返回null
	@Override
	public User selectUser(int userId) {
		// TODO Auto-generated method stub
		User user = reviewDao.selectUser(userId);
		if (user.getUserId() == 0 || "".equals(user.getUserPass())) {
			return null;
		}
		return user;
	}

	//根据adminId获取admin，如果没有值，返回null
	@Override
	public Admin selectAdmin(int adminId) {
		// TODO Auto-generated method stub
		Admin admin = reviewDao.selectAdmin(adminId);
		if (admin.getAdminId() == 0 || "".equals(admin.getAdminPass())) {
			return null;
		}
		return admin;
	}

	//根据newsId获取news，如果没有值，返回null
	@Override
	public News selectNews(int newsId) {
		// TODO Auto-generated method stub
		News news = reviewDao.selectNews(newsId);
		if (news.getNewsId() == 0) {
			return null;
		}
		return news;
	}

	//查询随机几条评论方法
	@Override
	public List<Review> likeSelectListReviewNum(int num) {
		// TODO Auto-generated method stub
		List<Review> reviewlist = reviewDao.likeSelectListReviewNum(num);
		if (reviewlist.size() == 0) {
			return null;
		}
		return reviewlist;
	}

	//根据新闻查评论方法
	@Override
	public List<Review> queryReviewInNews(int newsId) {
		// TODO Auto-generated method stub
		List<Review> reviewlist = reviewDao.queryReviewInNews(newsId);
		if (reviewlist.size() == 0) {
			return null;
		}
		return reviewlist;
	}

}
